package org.example.chat.entity;

import lombok.Data;
import org.example.chat.validate.groups.AddGroup;
import org.hibernate.annotations.Comment;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.time.LocalDate;

@Data
@Entity(name = "UserGroupRelation")
@Table(name = "user_group_relation", indexes = {
        @Index(name = "usergroup_relation_user_id_index",columnList = "user_id"),
        @Index(name = "usergroup_relation_group_id_index",columnList = "group_id")
})
public class UserGroupRelation implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id")
    private String id;

    @Column(name = "create_date")
    @Comment("加群时间")
    private LocalDate createDate;


    @NotEmpty(groups = {AddGroup.class}, message = "用户id不能为空！")
    @Column(name = "user_id", nullable = false)
    @Comment("用户id")
    private String userId;

    @NotEmpty(groups = {AddGroup.class}, message = "群组id不能为空！")
    @Column(name = "group_id", nullable = false)
    @Comment("群组id")
    private String groupId;

    @Length(max = 50, message = "备注最长50个字符")
    @Column(name = "user_nick", length = 50)
    @Comment("用户在群聊中的名称")
    private String userNick;
}
